package sy.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import sy.db.mysql.model.CDGL;
import sy.pageModel.DataGrid;
import sy.pageModel.Json;
import sy.pageModel.SessionInfo;
import sy.pageModel.Tree;
import sy.services.CDGLServiceI;
import sy.util.ConfigUtil;

/**
 *  @author zxl
 */
@Controller
@RequestMapping("/cdglController")
public class CDGLController extends BaseController {
	@Autowired
	public CDGLServiceI cDGLService;

	@RequestMapping("/dataGrid.shtml")
	@ResponseBody
	public DataGrid dataGrid(@RequestParam  Map param) {
		return cDGLService.findbyByGrid(param);
	}
	@RequestMapping("/tree")
	@ResponseBody
	public List<Tree> tree(HttpSession session) {
		SessionInfo sessionInfo = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		return cDGLService.tree(sessionInfo,2);
	}
	@RequestMapping("/add.shtml")
	@ResponseBody
	public Json add(CDGL t , HttpSession session,NativeWebRequest request) {
		
		Json j = new Json();
		try {
			cDGLService.insert(t);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
			j.setObj(t);
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/edit.shtml")
	@ResponseBody
	public Json edit(CDGL t , HttpSession session,NativeWebRequest request) {
		
		Json j = new Json();
		try {
			
			cDGLService.updateByPrimaryKeySelective(t);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
			j.setObj(t);
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/delete.shtml")
	@ResponseBody
	public Json delete(String id) {
		Json j = new Json();
		try {
			cDGLService.deleteByPrimaryKey(id);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/selectByid.shtml")
	@ResponseBody
	public CDGL selectByid(String id) {
		return cDGLService.selectByPrimaryKey(id);
	}
	
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/manager.shtml")
	public String manager() {
		return "/cDGL/cDGL";
	}
	
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/addPage.shtml")
	public String addPage(HttpServletRequest request) {
		CDGL cDGL  = new CDGL();
		
		request.setAttribute("cDGL", cDGL);
	return "/cDGL/cDGLAdd";
	}
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/editPage.shtml")
	public String editPage(String id ,HttpServletRequest request) {
		CDGL cDGL = this.cDGLService.selectByPrimaryKey(id);
		request.setAttribute("cDGL", cDGL);
		return "/cDGL/cDGLEdit";
	}
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/viewPage.shtml")
	public String viewPage(String id ,HttpServletRequest request) {
		CDGL cDGL = this.cDGLService.selectByPrimaryKey(id);
		request.setAttribute("cDGL", cDGL);
		return "/cDGL/cDGLView";
	}
}
